package com.yuyou.tas.admin.tool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import com.yuyou.tas.util.bean.ResBoolSimpleInfo;
import com.yuyou.tas.util.tool.LogUtil;

@Service
public class MailUtil {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());  
	
	@Autowired
	JavaMailSender mailSender;

	@Value("${mail.open}")
	private  String open;
	
	@Value("${denfind.env}")
	private  String denfindEnv;
	
	public ResBoolSimpleInfo<String> sendMonitorEmail(@RequestParam("subject") String subject,@RequestParam("content") String content){
		if(open.equals("on")){
			try {
				SimpleMailMessage message = new SimpleMailMessage();
				message.setFrom("zymonitor123@163.com");
				message.setTo("zymonitor123@163.com");
				message.setSubject(denfindEnv+":"+subject);
				message.setText(content);
				mailSender.send(message);
				return ResBoolSimpleInfo.getSuccessInfo();
			} catch (MailException e) {
				LogUtil.error(logger, "send commJobMail error:", e);
				return ResBoolSimpleInfo.getFailInfo(e.getMessage());
			}
		}
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
